import {Node, Prefab, Vec3} from 'cc';
import {CombinationHandler} from "db://assets/Scripts/MVC/Bullet/CombinationHandler";
import {BulletController} from "db://assets/Scripts/MVC/Bullet/BulletController";
import {PoolManager} from "db://assets/Scripts/framework/PoolManager";

/**
 * H型子弹策略
 */
export class HPolicy implements CombinationHandler {

    /**
     * H型子弹
     *
     * @param bulletPrefab 子弹模型
     * @param parent 父节点
     * @param playerNode 玩家节点
     * @param speed 移动速度
     */
    combination(bulletPrefab: Prefab, parent: Node, playerNode: Node, speed: Vec3): Node[] {
        // 创建子弹节点列表
        const bulletNodes: Node[] = [];

        // 创建2个子弹
        for (let i = 0; i < 2; i++) {
            // 创建子弹节点
            const bulletNode = PoolManager.getInstance().getNode(bulletPrefab, parent);
            // 设置移动速度
            const bulletController: BulletController = bulletNode.getComponent(BulletController);
            bulletController.uiState.speed = speed;
            // 添加至子弹节点列表
            bulletNodes.push(bulletNode);
        }

        // 设置子弹位置
        const position = playerNode.position;
        bulletNodes[0].setPosition(position.x - 0.5, position.y, position.z - 1);
        bulletNodes[1].setPosition(position.x + 0.5, position.y, position.z - 1);

        // 返回子弹节点列表
        return bulletNodes;
    }

}